<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<script language="javascript" src="/script/common.js" type="text/javascript"></script>
 	<meta name="author" content="zhbus-project">
 	<!--  zhbus-project 页面 -->
	<title>终端管理</title>
	<script type="text/javascript">	
	var org = Common.cOrg();	//当前单位	
	var qt = {};				//数据表格对象
	
	function load(){
		Eui.showNavigation();
		setPages(["listview","detview1","detview3"]);
		Common.initDict($("txaclForm").status,"pos_status","请选择");
		Common.initDict($("searchForm").status,"pos_status","全 部");
		
		//Templet.initDateInput("beginTime","交易起始时间","txaclForm","beginTxTime","_pastDate",true);
		//Templet.initDateInput("endTime","交易截止时间","txaclForm","endTxTime","_futureDate",true);
		var txacleType = Common.getItems("txacl_type")
		
		var html = '<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="label6">';
		html += "<tr>";	
		for (var i=0 ; i<txacleType.length; i++){
			var item = txacleType[i]
			if (i!=0&&i%4 == 0){
				html += "</tr><tr>";
			}
			html += "<td><input id='checkboxtxtype_"+item.code+"' name='checkboxtxtype' type='checkbox' value='"+item.code+"'> "+item.text+"</td>";
		}
		html += "</tr></table>"
		$("table_txAcl").innerHTML = html;
		
		var currencies = Common.getItems("currency")
			var html = '';	
			for (var i=0 ; i<currencies.length; i++){
				var item = currencies[i]
				html += "<input id='currencies_"+item.code+"' name='currencies' type='checkbox' value='"+item.code+"'>"+item.text;
			}
		$("currencies_span").innerHTML = html;
		createTable();
	}
	function createTable(){
		var columns = [];
		columns[0]={type:"checkbox"} 
		columns[1]={render:function(v,r){
			return "<a href=# onclick=\"onView("+r[0]+");return false;\">"+v+"</a>";	
		}}
		columns[6]={title:"操作",width:"15%",render:function(v,r){
			return "<a href=# onclick=\"onUpdatePos("+r[0]+");return false;\">分配终端</a> <a href=# onclick=\"onUpdatePage("+r[0]+");return false;\">修改终端</a>";
		},align:"center",order:false}
		qt = new QueryTable("pos_manage_query","searchForm","datalist",columns,{
			buttons:[
				{value:"添加终端",actions:onNew},
				{value:"删除终端",actions:onDelete}
			]
		});
	}
	function showData(){	
		qt.showTable();
	}
	function onView(id){
		DWR.call("posMgntService.getPosInfo",id,function(v){
			var pos = v.pos;
			pos.storeTime = pos.storeTime?pos.storeTime.format("yyyy-MM-dd hh:mm"):""
			pos.status = Common.getText("pos_status",pos.status);
			pos.specName = v.specName;
			pos.location = v.location;
			var txAcl = ""
			var list = pos.txAcl?pos.txAcl.split(","):[];
			for(var i=0; i<list.length; i++){
				if(txAcl)
					txAcl +="," 
				txAcl += Common.getText("txacl_type",list[i])
			}
			pos.txAcl = txAcl
			var currencies = ""
			var currencies_list = pos.currencies?pos.currencies.split(","):[];
			for(var i=0; i<currencies_list.length; i++){
				if(currencies)
					currencies +="," 
				currencies += Common.getText("currency",currencies_list[i])
			}
			pos.currencies = currencies
			Common.showDetail("pos_page3",pos);
		});
		switchPage("detview3");
	}
	function onNew(){
		$("txaclForm").reset();
		switchPage("detview1");
	}
	function onDelete(){
		var ids = qt.getBoxValue();
		if(ids){
			Eui.onDel("posMgntService.deletePos",ids, "终端", null, function() {
				qt.showTable();
			},qt.getBts());
		}else{
			showWarning("请选择要删除的终端");
		}
	}
	function onUpdatePos(id){
		SystemMgnt.selOrgList(function(v){
			if (!v) return;
			if(showQuestion("请确认是否分配到"+v.name+"?")){
				DWR.call("posMgntService.updatePosLoction",id,{id:v.id},function(){
					showInformation("分配成功");
					showData();
				});
			}
		},{selOne:true,orgId:org.id,onlyChildren:true})
	}
	function onUpdatePage(id){
		var cs = document.getElementsByName("checkboxtxtype");
		for (var i=0;i<cs.length;i++){
			var cb = cs[i];
			if (cb.checked){
				cb.checked = false ;
			}
		}
		DWR.call("posMgntService.getPosInfo",id,function(v){
			var pos = v.pos;
			pos.specName = v.specName;
			Common.setValues("txaclForm",pos);
			var txAcl = pos.txAcl;
			if (txAcl){
				var list = txAcl.split(",");
				for (var i=0;i<list.length;i++){
					var tx = list[i];
					$("checkboxtxtype_"+tx).checked = true;
				}
			}
			var currencies = pos.currencies;
			if (currencies){
				var list = currencies.split(",");
				for (var i=0;i<list.length;i++){
					var currency = list[i];
					$("currencies_"+currency).checked = true;
				}
			}
		});
		switchPage("detview1");
	}
	function onSave(){
		if(!checkForm("txaclForm"))return;
		var posValue = Common.getValues("txaclForm");
		var txAcl = ""
		var cbs = document.getElementsByName("checkboxtxtype");
		for (var i=0;i<cbs.length;i++){
			var cb = cbs[i];
			if (cb.checked){
				if (txAcl)
					txAcl += ","
				txAcl += cb.value;
			}
		}
		var currencies = "";
		var cbs = document.getElementsByName("currencies");
		for (var i=0;i<cbs.length;i++){
			var cb = cbs[i];
			if (cb.checked){
				if (currencies)
					currencies += ","
				currencies += cb.value;
			}
		}
		if (!currencies) {showWarning("至少选择一个币种！");return;}
		posValue.currencies = currencies;
		posValue.txAcl = txAcl;
		DWR.call("posMgntService.savePos",posValue,function(){
			showInformation("保存成功");
			switchPage("listview");
			showData();
			$("txaclForm").reset();
		});
	}
	function selPos(){
		var v = openDialogFrame("/basic/sel_pos.html?",'请选择终端规格',464,700)
		if(v){
			$("txaclForm").spec.value = v.id;
			$("txaclForm").specName.value = v.spec;
		}
	}

	//选择单位控件 回调方法
	function setOrg(sorg){
		$("searchForm").orgName.value = sorg.name;	
	}
	</script>
</head>
<body onload="load()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<!--查询静态页面部分-->
	<div id="listview">	
		<!--查询条件form-->
		<div class="searchForm">
			<form id="searchForm" name="searchForm" action="">
				<table cellSpacing="0" cellPadding="4" width="100%" border="0">
					<tr>
						<td><label>终端编号</label> <input type="text" name="uniqueId" maxlength="12" onblur="checkV(this,'number')"></td>
						<td><label>所属机构</label> <input type="text" name="orgName" maxlength="32"><a class="orga" href="#" onclick="SystemMgnt.selOrg(setOrg)">&nbsp;&nbsp;</a></td>
					</tr>
					<tr>	
						<td><label>终端名称</label> <input type="text" name="name" maxlength="32"></td>
						<td><label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label> <select name="status"></select></td>
						<td><button type="button" onclick="showData()">查 询</button></td>
					</tr>
				</table>
			</form>
		</div>
		<div id=datalist></div>
	</div>
	<div id="detview1" style="display:none;">
		<form id="txaclForm" name="txaclForm" action="">
			<input type="hidden" name="id"/>
			<input type="hidden" name="spec"/>
			<div class=form>
				<div class="formTitle">终端信息</div>
				<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="label6">
					<tr>
						<td><label>终端编号</label> <input name="uniqueId" onblur="checkV(this,'number',true)" maxlength="8"><span class="des">*</span></td>
						<td><label>终端名称</label> <input name="name" onblur="checkV(this,'',true)" maxlength="32"><span class="des">*</span></td>
					</tr>
					<tr>
						<td><label>终端规格</label> <input type="text" name="specName" readonly class="readonly" onblur="checkV(this,'',true)"/><a class=orga title="选择终端规格" href="javascript:void(0)" onclick="selPos()">&nbsp;&nbsp;</a><span class="des">*</span></td>
						<td><label>软件版本号</label> <input type="text" name="firmwareVer" maxlength="32"></td>
					</tr>
					<tr>
						<td id="beginTime"><label>交易起始时间</label> <input type="text" name="beginTxTime" onblur="checkV(this,'time')"/> <font color="red">提示:时间格式为 23:59:59</font></td>
						<td id="endTime"><label>交易截止时间</label> <input type="text" name="endTxTime" onblur="checkV(this,'time')"/> <font color="red">提示:时间格式为 23:59:59</font></td>
					</tr>
					<tr>
						<td><label>终端状态</label> <select name='status' onblur="checkV(this,'',true)"></select><span class='des'>*</span></td>
						<td><label>支持币种</label><span id="currencies_span"></span><span class='des'>*</span></td>
					</tr>
				</table>
			</div>
			<div class=form>
				<div class="formTitle">授权交易类型</div>
				<div id="table_txAcl">
				</div>
			</div>
			<p><button type="button" onclick='onSave()'>保 存</button>   <button name="button" onclick='switchPage("listview")'>取 消</button></p>
		</form>
	</div>
	<div id="detview3" style="display:none;" align=center>
		<form id="pos_page3" name="pos_page3" action="">
			<div class="form">
				<div class="formTitle">终端明细</div>	
				<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="viewTable">
					<tr>
						<td><label>终端编号</label> <span id="uniqueId" ></span></td>
			           	<td><label>终端名称</label> <span id="name" ></span></td>
					</tr>	
					<tr>
					 	<td><label>所属机构</label> <span id="location" ></span></td>
					   	<td><label>终端规格</label> <span id="specName" ></span></td>
					</tr>
					<tr>
					  	<td><label>状&nbsp;&nbsp;&nbsp;&nbsp;态</label> <span id="status" ></span></td>
					   	<td><label>生成日期</label> <span id="storeTime" ></span></td>
					</tr>
					<tr>
					   	<td><label>交易起始时间</label> <span id="beginTxTime" ></span></td>
						<td><label>交易截止时间</label> <span id="endTxTime" ></span></td>
					</tr>
					<tr>
					   	<td><label>软件版本号</label> <span id="firmwareVer" ></span></td>
						<td><label>支持币种</label> <span id="currencies" ></span></td>
					</tr>
				</table>
			</div>
			<div class=form>
				<div class="formTitle">授权交易类型</div>
				<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="viewTable">
					<tr>
						<td><label>授权交易类型</label><span id="txAcl" ></span></td>
					</tr>
				</table>
			</div>
			
			<p><button type="button" onclick="switchPage('listview')">返 回</button></p>
		</form>
	</div>
	</body>
</html>